
class CommonAjax {
    url="/"
    type="get"
    async=false
    data={}
    dataType="json"

    constructor (url) {
        this.url = url
    }


    invoke(successFunc,completeFunc){
        try {
            $.ajax({
                url: this.url,
                type: this.type,
                async: this.async,
                data:this.data,
                dataType:this.dataType,
                success: function (data) {

                    console.log(data);
                    //200  或 2004 接口返回成功，对象data需要调用方自己判断
                    var  code=data.code.toString()
                    if(code.startsWith("200")){
                        if(typeof successFunc == "function")
                            successFunc(data.data)
                    } else{
                        alert("接口请求code="+data.code)
                    }

                },
                complete:function () {
                    if(typeof completeFunc == "function")
                        completeFunc()
                }
            })
        }
        catch (e) {
            alert(e.toString())
        }
        finally {

        }
    }

}